package com.example.demo.service.Impl;

import com.example.demo.bean.BaseFile;
import com.example.demo.bean.BaseFileExample;
import com.example.demo.dao.BaseFileMapper;
import com.example.demo.service.IBaseFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class BaseFileServiceImpl implements IBaseFileService {
    @Autowired
    private BaseFileMapper baseFileMapper;
    @Override
    public List<BaseFile> query(String file_name) {
        BaseFileExample example = new BaseFileExample();
        if (!StringUtils.isEmpty(file_name)) {
            example.createCriteria().andFileNameLike("%" + file_name + "%");
        }
        List<BaseFile> list = baseFileMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseFile baseFile) {
        if(baseFile.getId()==null){
            baseFileMapper.insert(baseFile);
        }else{
            baseFileMapper.updateByPrimaryKey(baseFile);
        }

    }


    @Override
    public void deleteById(String id) {
        baseFileMapper.deleteByPrimaryKey(id);
    }

}
